import { ApiCall } from "tsrpc";
import { ReqBuy, ResBuy } from "../../../../shared/master/shop/skill/PtlBuy";
import god from "../../../../god";
import { player } from "../../../../model/fight/body/player";
import { template } from "../../../../shared/master/MsgAction";

export default async function (call: ApiCall<ReqBuy, ResBuy>) {
    call.succ({})
    let user = call.req._player as player;
    let idx = call.req.idx;
    const item = god.shop_skill.items[idx - 1];
    if (!item) {
        user.sendMsg(template.default, `购买失败:主神商店 ID${idx}的商品已售完`)
        return;
    }
    let jude = user.check_wallet(item.value * item.num, 0, [], false, `主神商店购买${item.getStyleName()}X${item.num}`,true)
    if (!jude.state) {
        return;
    }
    god.shop_skill.items[idx - 1] = undefined;
    user.getBag().add(item);
}